import http from "@/utils/http";
// import axios from "axios";

export default {
  namespaced: true,

  state: {
    userList: [], // 正式用户数据
    accountRecordList: [], // 账变记录
    upDownList: [], //上下分记录
    ReceivablesList: [], //收款账户
    lotteryList: [] // 彩种记录
  },
  mutations: {
    SETUSERLIST(state, list) {
      state.userList = list;
    },
    SETCHANGELISTS(state, list) {
      state.userList = list;
    },
    SETQUERYLISTS(state, list) {
      state.userList = list;
    },
    SETACCOUNTRECORDLISTS(state, list) {
      state.accountRecordList = list;
    },
    QUERYUPDOWNLISTS(state, list) {
      state.upDownList = list;
    },
    SETUPDOWNLISTS(state, list) {
      state.upDownList = list;
    },
    SETRECEIVABLESLISTS(state, list) {
      state.ReceivablesList = list;
    },
    SETLOTTERYLISTS(state, list) {
      state.lotteryList = list;
    },
    QUERYLOTTERYLISTS(state, list) {
      state.lotteryList = list;
    }
  },

  actions: {
    getUserList({ commit },{id,nickname,page}) {
      let token=sessionStorage.getItem('token')
      let account=JSON.parse(localStorage.getItem('account'));
      http
        .post(
          `/api/login/room_user/get_agent_room_user_list?token=${token}&agent_account_id=${account.id}&nickname=${nickname}&page=${page}`
        )
        .then(response => {
          let res = response.data.list;
          console.log(response);
          commit("SETUSERLIST", res);
        });
    },
    getChangeList({ commit }, index) {
      let selectList = ["asc", "desc", "get_list", "get_status", "get_robot"];
      let url = selectList[index];
      // console.log(url)
      let token=sessionStorage.getItem('token')
      http
        .post(
          `/api/login/room_user/${url}?token=${token}`
        )
        .then(response => {
          // console.log(response);
          console.log(response.data);
          if (index == 3) {
            let res = response.data.list.data;
            commit("SETCHANGELISTS", res);
          } else {
            let res = response.data.list;
            // console.log(res)
            commit("SETCHANGELISTS", res);
          }
        });
    },
    getQueryList({ commit }, { userValue, isRobot, status }) {
      // console.log(par)
      let token=sessionStorage.getItem('token')
      http
        .post(
          `/api/login/room_user/info?account_id=${userValue}&is_robot=${isRobot}&status=${status}&token=${token}`
        )
        .then(response => {
          console.log(response);
          let res = response.data.data;
          console.log(res);
          commit("SETQUERYLISTS", res);
        });
    },
    getaccountRecordList({ commit }, { adr, id }) {
      let token=sessionStorage.getItem('token')
      http
        .post(
          `/api/login/balance_change/${adr}?account_id=${id}&token=${token}`
        )
        .then(response => {
          console.log(response);
          let res = response.data.list;
          if (res.length == 0) {
            commit("SETACCOUNTRECORDLISTS", res);
          } else {
            commit("SETACCOUNTRECORDLISTS", res.data);
          }
          // console.log(res);
        });
    },
    getUpDownList({ commit }, { adr, id }) {
      let token=sessionStorage.getItem('token')
      http
        .post(
          `/api/login/add_balance/${adr}?account_id=${id}&token=${token}`
        )
        .then(response => {
          console.log(response);
          let res = response.data;
          console.log(res);
          commit("SETUPDOWNLISTS", res);
        });
    },
    getReceivablesList({ commit }, id) {
      let token=sessionStorage.getItem('token')
      http
        .post(
          `/api/login/room_user/pay_account?account_id=${id}&token=${token}`
        )
        .then(response => {
          let res = response.data.data;
          console.log(res);
          commit("SETRECEIVABLESLISTS", res);
        });
    },
    getLotteryList({ commit }, { adr, id, index }) {
      let token=sessionStorage.getItem('token')
      http
        .post(
          `/api/rule/user_bet/${adr}?token=${token}`,
          {
            account_id: id,
            lottery: index + 1
          }
        )
        .then(response => {
          let res = response.data.list;
          console.log("在这里",res);
          commit("SETLOTTERYLISTS", res);
        });
    },
    queryLotteryList({ commit }, { item, index, star, end, period }) {
      let token=sessionStorage.getItem('token')
      http
        .post(
          `/api/rule/user_bet/inquire?token=${token}`,
          {
            account_id: item.account_id,
            lottery: index + 1,
            star: star,
            end: end,
            period: period
          }
        )
        .then(response => {
          let res = response.data.list;
          console.log(res);
          commit("QUERYLOTTERYLISTS", res);
        });
    },
    queryUpDownList({ commit }, { star, end, account_id }) {
      let token=sessionStorage.getItem('token')
      http
        .post(
          `/api/login/add_balance/time_find?token=${token}`,
          {
            account_id,
            star,
            end
          }
        )
        .then(response => {
          console.log(response);
          let res = response.data;
          console.log(res);
          commit("QUERYUPDOWNLISTS", res);
        });
    }
  }
};
